package com.fy.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fy.module.sys.entity.SysCode;
import com.fy.module.sys.mapper.CodeMapper;
import com.fy.module.sys.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 江迪
 */
@Service
public class CodeServiceImpl extends ServiceImpl<CodeMapper, SysCode> implements ICodeService {
    @Override
    public int addVerifyCode(SysCode sysCode) {
        if (null == sysCode) {
            return -1;
        }
        int index = this.baseMapper.insert(sysCode);
        if(index>0){
            return index;
        }
        return -1;
    }

    @Override
    public SysCode getVerifyCodeByCodeName(String code) {
        if (null == code) {
            return null;
        }
        QueryWrapper<SysCode> queryWrap=new QueryWrapper();
        SysCode sysCode = this.baseMapper.selectOne(queryWrap.eq("code_name", code));
        if(sysCode!=null){
            return sysCode;
        }
        return null;
    }

    @Override
    public int deleteVerifyCode(String code) {
        if (null == code) {
            return -1;
        }
        UpdateWrapper<SysCode> updateWrapper=new UpdateWrapper<>();
        int index = this.baseMapper.delete(updateWrapper.eq("code_name", code));
        if(index>0){
            return index;
        }
        return -1;
    }

    @Override
    public List<SysCode> selectCodeList() {
        QueryWrapper<SysCode> queryWrapper=new QueryWrapper<>();
        List<SysCode> sysCodes = this.baseMapper.selectList(queryWrapper);
        return sysCodes;
    }

}
